/* eslint-disable no-lonely-if */
import React, { Component } from "react";
import "./header.scss";
// import './global.scss';
export default class Header extends Component {
	//头部标题
	constructor(props) {
		super(props);
	}

	gobackHandle() {
		if (this.props.objParams.isModal) {
			this.props.handleBack();
		} else {
			window.history.back();
		}
	}

	render() {
		let {
			phoneStyle,
			blueStyle,
			back,
			goToback,
			goToApp,
			title,
			rightText,
			isOverdue,
			leftPathName,
			rightPathName,
			rightClickText,
			rightClick
		} = this.props.objParams;
		let classStyle;

		if (phoneStyle && phoneStyle == true) {
			//iphoneX
			if (blueStyle && blueStyle == "blue") {
				//蓝色背景
				classStyle = "head-list-blue h168";
			} else if (blueStyle && blueStyle == "white") {
				//蓝色背景
				classStyle = "head-list-white h168";
			} else {
				//黑色背景
				classStyle = "head-list h168";
			}
		} else {
			//普通手机
			if (blueStyle && blueStyle == "blue") {
				//蓝色背景
				classStyle = "head-list-blue h128";
			} else if (blueStyle && blueStyle == "white") {
				//蓝色背景
				classStyle = "head-list-white h128";
			} else {
				//黑色背景
				classStyle = "head-list h128";
			}
		}

		return (
			<header id="header" className={classStyle}>
				{goToback && (
					<span
						className="head_goback left"
						id="headBackBtn"
						onClick={() => {
							if (this.props.propsObj) {
								switch (this.props.propsObj.homeServiceDatas.selectedTab) {
									case "homeTab":
										this.props.propsObj._homeServiceDatas({
											selectedTab: "homeTab", //默认选中的tab
											selectedTabTile: "首页" //默认选中的tabTile
										});
										break;
									case "lifeTab":
										this.props.propsObj._homeServiceDatas({
											selectedTab: "lifeTab", //默认选中的tab
											selectedTabTile: "生活服务" //默认选中的tabTile
										});
										break;
									case "creditTab":
										this.props.propsObj._homeServiceDatas({
											selectedTab: "creditTab", //默认选中的tab
											selectedTabTile: "信用卡" //默认选中的tabTile
										});
										break;
									case "myTab":
										this.props.propsObj._homeServiceDatas({
											selectedTab: "myTab", //默认选中的tab
											selectedTabTile: "个人中心" //默认选中的tabTile
										});
										break;
									default:
										this.props.propsObj._homeServiceDatas({
											selectedTab: "homeTab", //默认选中的tab
											selectedTabTile: "首页" //默认选中的tabTile
										});
										break;
								}
							}
							window.location.replace(leftPathName);
						}}
					></span>
				)}
				{back && (
					<span
						className="head_goback left"
						id="headBackBtn"
						onClick={this.gobackHandle.bind(this)}
					></span>
				)}
				{goToApp && (
					<span
						className="head_goback left"
						id="headBackBtn"
						onClick={() => {
							window.YHAuthorize.callHandler("SDK_ClosePage", {}, () => {});
						}}
					></span>
				)}
				{title && <span className="head_title ellips">{title}</span>}
				{rightText && (
					<span
						className="right right-text"
						onClick={() => {
							window.location.replace(rightPathName);
						}}
					>
						{isOverdue && isOverdue == "4" ? <i className="red"></i> : <i></i>}
						{rightText}
					</span>
				)}
				{rightClickText && (
					<span className="right right-text" onClick={rightClick}>
						{rightClickText}
					</span>
				)}
			</header>
		);
	}
}
